package com.zlzxm.lock;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;

import pub.devrel.easypermissions.AppSettingsDialog;

public class MainActivity extends BaseActivity {

    boolean isFirst = true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        isFirst =  sharedPreferences.getBoolean("isFirst",true);

        if(isFirst) {
            new AppSettingsDialog
                    .Builder(this)
                    .setTitle("权限请求")
                    .setRationale("引导您请前往权限中心打开所需权限(后台，锁屏)，若无此权限请无视")
                    .setPositiveButton("好")
                    .setNegativeButton("取消")
                    .build()
                    .show();
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

            startForegroundService(new Intent(MainActivity.this,LockService.class));

        }else {

            startService(new Intent(MainActivity.this,LockService.class));
        }

        if(!isFirst) {
            finish();
        }

        SharedPreferences.Editor  edit=  sharedPreferences.edit();
        edit.putBoolean("isFirst",false);
        edit.apply();

    }


}
